package com.aiyige.page.player;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.vondear.rxtools.RxFileTool;

import java.io.Serializable;

/**
 * Created by xiachao on 2017/11/14.
 */

public class PlayerInfo implements MultiItemEntity ,Serializable {
    public PlayerInfo() {
    }

    public PlayerInfo(String path, String title, String cover, boolean isFree) {
        this.path = path;
        this.title = title;
        this.isFree = isFree;
        this.cover  = cover;
    }

    private PlayerInfo(Builder builder) {
        setPath(builder.path);
        setTitle(builder.title);
        setFree(builder.isFree);
        setCover(builder.cover);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getPath() {
        return TextUtils.isEmpty(path)?"":path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    private String path;

    public String getTitle() {
        return TextUtils.isEmpty(title)?"":title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    private String title;

    public boolean isFree() {
        return isFree;
    }

    public void setFree(boolean free) {
        isFree = free;
    }

    private boolean isFree;

    public String getCover() {
        return TextUtils.isEmpty(cover)?"":cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    private String cover;

    @Override
    public int getItemType() {
        return 0;
    }

    /**
     * 1、路径不为空
     * 2、不是http开头
     * 3、文件存在本地
     * @return true
     */
    public boolean isLocalVideoAndExist() {
        return !TextUtils.isEmpty(path) && !path.startsWith("http") && RxFileTool.fileExists(path);
    }


    public static final class Builder {
        private String path;
        private String title;
        private boolean isFree;
        private String cover;

        private Builder() {
        }

        public Builder path(String path) {
            this.path = path;
            return this;
        }

        public Builder title(String title) {
            this.title = title;
            return this;
        }

        public Builder isFree(boolean isFree) {
            this.isFree = isFree;
            return this;
        }

        public Builder cover(String cover) {
            this.cover = cover;
            return this;
        }

        public PlayerInfo build() {
            return new PlayerInfo(this);
        }
    }
}
